﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._18_迭代器模式
{
    /// <summary>
    /// 具体迭代器
    /// </summary>
    public class BookShelfIterator:IIterator<Book>
    {
        private readonly BookShelf _bookShelf;
        private int _index = 0;

        public BookShelfIterator(BookShelf bookShelf)
        {
            _bookShelf = bookShelf; 
        }

        public bool HasNext()
        {
            return _index < _bookShelf.Count;
        }

        public Book Next()
        {
            Thread.Sleep(500); // 模拟延迟
            return _bookShelf[_index++];
        }



    }
}
